package com.cater.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.common.BaseEntity;
import com.cater.common.PageResult;
import com.cater.query.CommonQuery;
import com.cater.sys.dao.LanguageDao;
import com.cater.sys.entity.Language;
import com.cater.sys.service.BaseService;

/**
 * @author yong
 * @Date 2018年3月23日-上午10:54:02
 */
@Service
public class LanguageServiceImpl implements BaseService<Language, CommonQuery, String> {
	@Autowired
	LanguageDao dao;

	@Override
	public PageResult<Language> findPageResult(CommonQuery query) {
		PageResult<Language> result = new PageResult<Language>();
		result.setPage(query.getPage());
		result.setPageSize(query.getRows());
		int count = dao.findCount(query);
		int first = (query.getPage() - 1) * query.getRows();
		int max = query.getRows();
		List<Language> list = dao.findList(query, first, max);
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	@Override
	public List<Language> getAll() {
		return dao.getAll();
	}

	@Override
	public List<Language> getAllCommon(CommonQuery query) {
		return dao.getAllCommon(query);
	}

	@Override
	public int save(Language t) {
		return 0;
	}

	@Override
	public String saves(Language t) {
		BaseEntity.getCreate(t);
		dao.save(t);
		return t.getId();
	}

	@Override
	public void update(Language t) {
		BaseEntity.getupdate(t);
		dao.update(t);
	}

	@Override
	public void delete(String id) {
		dao.delete(id);
	}

	@Override
	public Language getById(String id) {
		return dao.getById(id);
	}

	public List<Language> getByPid(CommonQuery query) {
		return dao.getBypid(query);
	}

	public Language getMaxSort(CommonQuery query) {
		return dao.getMaxSort(query);
	}

	public Language getByParent(CommonQuery query) {
		return dao.getByParent(query);
	}
}
